package com.wc.alorithm_luogu.P1614;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/21 14:59
 * @description https://www.luogu.com.cn/problem/P1614
 * 爱与愁的心痛
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] array = new int[n];

        int min = 0;

        int curSum = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        // 第一个连续m的和
        for (int i = 0; i < m; i++) {
            min += array[i];
        }
        curSum = min;

        // 滑动计算
        for (int i = m; i < n; i++) {
            curSum -= array[i - m];
            curSum += array[i];
            min = Math.min(min,curSum);
        }

        System.out.println(min);
    }
}
